extends Node2D
class_name BaseStage

@export var dialogue_area:Array[Area2D]
@export var dialogue_count:int

@export var start_emotion:Npc.Emotion
@export var current_npc:Npc
@export var stage_bgm:AudioStream
@onready var spawn_point: Node2D = $SpawnPoint
@onready var base_stage: BaseStage = $"."
@onready var fake_bg: Node2D = $FakeBg

var current_count:int = 0

func _ready() -> void:
	MusicPlayer.play_bgm(stage_bgm)
	fake_bg.visible = true
	Global.player.global_position = spawn_point.global_position
	current_npc.change_emotion(start_emotion)
	DialogHandler.dialogue_end.connect(on_dialogue_end.unbind(1))
	GameEvents.stage_entered.emit()
	SaveManager.save_game()
	if Global.player.global_position == spawn_point.global_position && name != "Stage5":
		Global.player.is_dead = false
	
	




	


#func _process(delta: float) -> void:
	#if Global.player != null && Global.player.global_position.distance_squared_to(current_npc.global_position) < pow(1280,2):
		#if fake_bg.visible:
			#fake_bg.visible = false

func delete_dialogue_area(count: int) -> void:
	current_count = count
	for i in range(0,current_count):
		dialogue_area[i].queue_free()
	Global.main.divider_seven()




func on_dialogue_end() -> void:
	current_count += 1
	if current_count >= dialogue_count:
		Global.player.is_dead = true
		get_parent().stage_end.emit()
